package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.TInform;
import cn.wolfcode.trip.base.query.MessageQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IMessageService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private IMessageService messageService;

    @RequestMapping("/sysMsgList")
    public String sysMsgList(@ModelAttribute("qo") MessageQueryObject qo, Model model){
        PageInfo sysMsg = messageService.getSysMsg(qo);
        model.addAttribute("pageInfo",sysMsg);
        return "/systemMessage/list";
    }


    //添加系统消息
    @RequestMapping("/saveSysMsg")
    @ResponseBody
    public Object saveSysMsg(TInform inform){
        JSONResult json = new JSONResult();
        //设置创建日期
        inform.setCreatTime(new Date());
        //设置为系统消息
        inform.setToAll(1);
        try{
        messageService.insertInform(inform);
        }catch (Exception e){
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

}
